from plotting.drawer import plot_gantt_chart, draw_precedence_relations
from solution_methods.GA.run_GA import run_GA
from solution_methods.GA.src.initialization import initialize_run
from solution_methods.helper_functions import load_job_shop_env, load_parameters

if __name__ == '__main__':
    # freeze_support() # 关闭之后，貌似也能正常工作

    # 遗传算法
    parameters = load_parameters("configs/GA.toml")
    jobShopEnv = load_job_shop_env(parameters['instance'].get('problem_instance'))
    draw_precedence_relations(jobShopEnv)

    population, toolbox, stats, hof = initialize_run(jobShopEnv, **parameters)
    makespan, jobShopEnv = run_GA(jobShopEnv, population, toolbox, stats, hof, **parameters)

    print("GA遗传算法，最小化最大完工时间——makespan:" + str(makespan))

    # print(jobShopEnv)
    # print(jobShopEnv.jobs)
    # print(jobShopEnv.machines)

    plot_gantt_chart(jobShopEnv)
